/**
 * Copyright(c) 2015 Jade Techonologies Co., Ltd.
 *
 * History:
 *   14-8-22 下午3:43 Created by lyyang
 */
package com.jade.framework.base.util;


import com.jade.framework.base.lang.Hex;

/**
 * 格式化输出
 *
 * @author <a href="mailto:lyyang@jade.com">lyyang</a>
 * @version 1.0 14-8-22 下午3:43
 */
public class FormatUtils
{
    public static String formatBytes(int lineSize,byte... bytes){
        if (bytes==null||bytes.length==0){
            return "";
        }
        int i = 0;
        String result = "";
        for (byte b:bytes){
            String tmp = Integer.toHexString(b);
            if (tmp.length()==1){
                tmp = "0"+tmp;
            }
            else if (tmp.length()>2){
                tmp = tmp.substring(tmp.length()-2);
            }
            result += tmp + " ";
            if (i++==lineSize){
                result += "\n";
                i = 0;
            }
        }
        return result.toUpperCase();
    }

    public static void main(String[] args){
        byte[] bytes = {(byte)0x0f,(byte)0xff};
        System.out.println(Hex.encode(bytes));
    }
}
